﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Abstract
{
    class Stock
    {
        private static int mCount = 4 ;
        private static Stock _instance;
        private static Queue _coupeStock = new Queue(mCount);
        private static Queue _miniStock = new Queue(mCount);
        private static Queue _sedanStock = new Queue(mCount);

        protected Stock() { }
        public static Stock getInstance()
        {
            if (_instance == null)
            {
                _instance = new Stock();
            }
            return _instance;
        }

        public void AddToStock(AbstractCar.Cars type, AbstractCar car)
        {
            if(type == AbstractCar.Cars.Sedan && _sedanStock.Count < mCount)
            {
                _sedanStock.Enqueue(car);
            }

            if (type == AbstractCar.Cars.Mini && _miniStock.Count < mCount)
            {
                _miniStock.Enqueue(car);
            }
            if (type == AbstractCar.Cars.Coupe && _coupeStock.Count < mCount)
            {
                _coupeStock.Enqueue(car);
            }
        }

        public AbstractCar RetriveFromStock(AbstractCar.Cars type)
        {
            AbstractCar car = null;


            if (type == AbstractCar.Cars.Sedan && _sedanStock.Count > 0)
            {
                car = (Sedan)_sedanStock.Dequeue();
                return car;
            }
            if (type == AbstractCar.Cars.Mini && _miniStock.Count > 0)
            {
                car=(Mini)_miniStock.Dequeue();
                return car;
            }
            if (type == AbstractCar.Cars.Coupe && _coupeStock.Count > 0)
            {
                car=(Coupe)_coupeStock.Dequeue();
                return car;
            }

            return car;
        }
    }
}
